/**
 * title: 点击上传
 * desc: 经典款式，用户点击按钮弹出文件选择框。
 */

import React from 'react';
import { message, Button } from 'antd';
import { UploadOutlined } from '@ant-design/icons';
import Upload, { FileChunkUploadProps } from 'react-file-chunk-upload';

const props: FileChunkUploadProps = {
  urlStartFiles: 'http://localhost:59011/multipart-uploads/start',
  urlUploadChunk: 'http://localhost:59011/multipart-uploads/chunk',
  urlAssembleFile: 'http://localhost:59011/multipart-uploads/assemble',
  onChange(info: any) {
    if (info.file.status !== 'uploading') {
      console.log(info.file, info.fileList);
    }
    if (info.file.status === 'done') {
      message.success(`${info.file.name} file uploaded successfully`);
    } else if (info.file.status === 'error') {
      message.error(`${info.file.name} file upload failed.`);
    }
  },
};

export default () => (
  <Upload {...props}>
    <Button icon={<UploadOutlined />}>Click to Upload</Button>
  </Upload>
);
